<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var win = null;
        function openWin() {
            console.log("open win")
            win = window.open("https://qq.com");
        }
        function closeWin() {
            if (win !== null) {
                //console.log("close win", win);
                win.close();
                win = null;
            }
        }
        function openAndClose() {
            openWin();
            closeWin();
        }
    </script>
    <button onclick="openWin()">打开窗口</button>
    <button onclick="closeWin()">关闭窗口</button>
    <button onclick="openAndClose()">打开并关闭窗口</button>

</body>

</html>